import type { GridItemProps } from 'naive-ui/lib/grid';

import type FormFieldType from '@/components/form/src/types/field-type';
import type { BasicFormProps } from '@/components/form/src/props';

export interface FormSchema {
  display?: boolean | ControlFunction<Recordable>;
  field: string;
  label: string;
  labelMessage?: string;
  labelMessageStyle?: object | string;
  defaultValue?: any;
  component: FormFieldType;
  componentProps?: Recordable;
  slot?: string;
  rules?: object | object[];
  giProps?: GridItemProps;
  isFull?: boolean;
  suffix?: string;
}

export interface FormActionType {
  submit: () => Promise<any>;
  setProps: (formProps: Partial<BasicFormProps>) => Promise<void>;
  setSchema: (schemaProps: Partial<FormSchema[]>) => Promise<void>;
  setFieldsValue: (values: Recordable) => void;
  clearValidate: (name?: string | string[]) => Promise<void>;
  getFieldsValue: () => Recordable;
  resetFields: () => Promise<void>;
  validate: (nameList?: any[]) => Promise<any>;
  setLoading: (status: boolean) => void;
}

export type RegisterFn = (formInstance: FormActionType) => void;

export type UseFormReturnType = [RegisterFn, FormActionType];
